package cn.com.template.utils;

import static cn.com.support.message.MessageCodeEnum.ERROR_SELECT;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.com.commons.Paginator;
import cn.com.template.ui.Flexigrid;

/**
 * Flexigrid数据封装UTIL类
 * @author Zoe
 *
 */
public class FlexigridUtil {

	private static Logger logger = LoggerFactory.getLogger(FlexigridUtil.class);
	
	private int page;
	private int rp;
	private int total;
	private String qtype;
	private String query;
	private String sortname;
	private String sortorder;
	
	public FlexigridUtil() {
		super();
	}

	/**
	 * 将Paginator分页数据格式化成FLEXIGRID显示的数据
	 * @param result
	 * @param currendPage：当前页
	 * @return Map<String, Object>
	 */
	public static <T, C> Flexigrid formatFlexigridData(Paginator<C, List<T>> paginator){
		//定义分页数据Map对象
		Flexigrid flexigrid = null;
		//定义分页ROW对象
		//存储datagird每行数据CELL+ID
		List<Object> rowLst = new ArrayList<Object>();
		try {
			List<T> resultLst = paginator.getResult();
			int count = paginator.getTotalItems();
			for(T obj : resultLst){
				rowLst.add(obj);
			}
			//PACKAGE FLEXIGRID分页数据对象
			//page total rows
			flexigrid = new Flexigrid(paginator.getCurrentPage(), count, rowLst);
		} catch (Exception e) {
			logger.error(String.format(ERROR_SELECT.descript() + ":[%s] in formatFlexigridData:", e));
		}
		//return flexigrid
		return flexigrid;
	}
	
	//GET SET
	
	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRp() {
		return rp;
	}

	public void setRp(int rp) {
		this.rp = rp;
	}

	public String getQtype() {
		return qtype;
	}

	public void setQtype(String qtype) {
		this.qtype = qtype;
	}

	public String getQuery() {
		return query;
	}

	public void setQuery(String query) {
		this.query = query;
	}

	public String getSortname() {
		return sortname;
	}

	public void setSortname(String sortname) {
		this.sortname = sortname;
	}

	public String getSortorder() {
		return sortorder;
	}

	public void setSortorder(String sortorder) {
		this.sortorder = sortorder;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

}
